﻿using CefSharp;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace QRReader200
{
    public class MyStringVisitor : IStringVisitor
    {
        public MyStringVisitor(string url)
        {
            this.url = url;
        }
        private string url;
        public void Dispose()
        {
        }

        public void Visit(string str)
        {
            string tempPath = Path.Combine(Application.StartupPath, "temp_htmls");
            if (!Directory.Exists(tempPath))
            {
                Directory.CreateDirectory(tempPath);
            }
            string pattern = "^https://www.douban.com/people/(?<id>\\d+)/$";
            Regex regex = new Regex(pattern);
            Match match = regex.Match(url);
            if (match.Success)
            {
                string fn = Path.Combine(tempPath, match.Groups["id"].Value + ".html");
                File.WriteAllText(fn, str, System.Text.Encoding.UTF8);
            }
        }
    }
}
